package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.JsFirst;
import com.ruoyi.service.fanruan.IJsFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 建设集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/js")
public class JsFirstController extends BaseController
{
    private String prefix = "fanruan/js";

    @Autowired
    private IJsFirstService jsFirstService;

    @RequiresPermissions("fanruan:js:view")
    @GetMapping()
    public String js()
    {
        return "fanruan/js/js";
    }

    /**
     * 查询建设集团列表
     */
    @RequiresPermissions("fanruan:js:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JsFirst jsFirst)
    {
        startPage();
        List<JsFirst> list = jsFirstService.selectJsFirstList(jsFirst);
        return getDataTable(list);
    }

    /**
     * 导出建设集团列表
     */
    @RequiresPermissions("fanruan:js:export")
    @Log(title = "建设集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JsFirst jsFirst)
    {
        List<JsFirst> list = jsFirstService.selectJsFirstList(jsFirst);
        ExcelUtil<JsFirst> util = new ExcelUtil<JsFirst>(JsFirst.class);
        return util.exportExcel(list, "js");
    }

    /**
     * 新增建设集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/js/add";
    }

    /**
     * 新增保存建设集团
     */
    @RequiresPermissions("fanruan:js:add")
    @Log(title = "建设集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JsFirst jsFirst)
    {
        return toAjax(jsFirstService.insertJsFirst(jsFirst));
    }

    /**
     * 修改建设集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JsFirst jsFirst = jsFirstService.selectJsFirstById(id);
        mmap.put("jsFirst", jsFirst);
        return "fanruan/js/edit";
    }

    /**
     * 修改保存建设集团
     */
    @RequiresPermissions("fanruan:js:edit")
    @Log(title = "建设集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JsFirst jsFirst)
    {
        return toAjax(jsFirstService.updateJsFirst(jsFirst));
    }

    /**
     * 删除建设集团
     */
    @RequiresPermissions("fanruan:js:remove")
    @Log(title = "建设集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jsFirstService.deleteJsFirstByIds(ids));
    }
}
